<style lang="sass" scoped>
    .common_block{
        .head{
            .pink{
                color:pink;
            }
            i{
                font-size: 16px;
                margin-left: 6px;
                margin-right: 0;
            }
        }
    }
    .add{
        width: 100%;
        height:60px;
        line-height:60px;
        background: #409EFF;
        margin-top:10px;
        margin-bottom:10px;
        color:#fff;
        text-align: center;
        cursor: pointer;
    }
    .iconfont{
        font-size:25px;
        cursor:pointer;
        text-decoration:none;
        color:#666;
    }
</style>
<template>
    <div class="container pd15">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
            <el-form-item label="设备型号：" prop="device">
                <el-input v-model.trim="ruleForm.device"></el-input>
            </el-form-item>
            <el-form-item label="内容：" prop="content">
                <editor :content.sync="ruleForm.content"></editor>
            </el-form-item>
            <el-form-item label="">
                <el-button @click="add('ruleForm')" v-if="!$route.query.id" class="ml20" type="primary" :plain="false" round>提交</el-button>
                <el-button @click="edit('ruleForm')" v-else class="ml20" type="primary" :plain="false" round>提交</el-button>
            </el-form-item>

        </el-form>
    </div>
</template>
<script>
    import editor from 'components/editor';
    export default {
        components: {
            editor
        },
        data() {
            return {
                ruleForm: {
                    device:'',//	是	string	设备型号
                    content:'',//	是	string	内容
                },
                rules: {
                    companyName: [
                        { required: true, message: '请输入分销商名称', trigger: 'blur' },
                    ],                 
                },
            }
        },
        watch: {},
        created() {

        },
        mounted() {
            this.$nextTick(() => { 
                if(this.$route.query.id){
                    this.getInfo()
                }
            });
        },
        methods: {
            add(formName){
                this.$refs[formName].validate((valid) => {
                    let param = JSON.parse(JSON.stringify(this.ruleForm));
                    if (valid) {
                        util.ajax({
                            url:config.baseApi + 'bookMall-admin/api/network/addDeviceNetwork',
                            data:param,
                            success:()=>{
                                popup.miss({content:'新增成功'});
                                router.go(-1)
                            }
                        })
                    }
                })
            },
            edit(formName){
                this.$refs[formName].validate((valid) => {
                    let param = JSON.parse(JSON.stringify(this.ruleForm));
                    param.id = this.$route.query.id;
                    if (valid) {
                        util.ajax({
                            url:config.baseApi + 'bookMall-admin/api/network/updateDeviceNetwork',
                            data:param,
                            success:()=>{
                                popup.miss({content:'修改成功'});
                                router.go(-1)
                            }
                        })
                    }
                })
            },
            getInfo(){
                util.ajax({
                    url:config.baseApi + 'bookMall-admin/api/network/getDeviceNetworkDetail',
                    data:{
                        id:this.$route.query.id
                    },
                    success:(data=>{
                        this.ruleForm = {
                            device:data.data.device,
                            content:data.data.content,
                        }
                    })
                })
            }
        }
    };
</script>